package com.springjooq.sdun.config.properties;

import cn.stylefeng.roses.core.util.ToolUtil;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.models.auth.In;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.File;
import java.lang.reflect.Field;

import static cn.stylefeng.roses.core.util.ToolUtil.getTempPath;
/**
 * @Description Sdun 项目配置
 * @auther Szper
 * @create 2019-08-29 15:09
 */
@Component
@ConfigurationProperties(prefix = SdunProperties.PREFIX)
public class SdunProperties {
    public static final String PREFIX = "sdun";
    private Boolean kaptchaOpen = false;
    private Boolean swaggerOen = false;
    private String fileUploadPath;
    private Boolean haveCreatePath = false;
    private Boolean springSessoinOpen = false;
    /**
     * 定义session失效时间 默认30分钟 单位：秒
     */
    private Integer sessionValidateTime = 30 * 60;
    /**
     * session验证失效时间 (默认15分钟 单位：秒)
     */
    private Integer sessionValidationInterval = 15 * 60;

    /**
     * 获取上传路径
     */
    public String getFileUploadPath(){
        //无路径保存到临时路径
        if (ToolUtil.isEmpty(fileUploadPath)) {
            return ToolUtil.getTempPath();
        } else {
            //判断结尾符有无
            if (!fileUploadPath.endsWith(File.separator)) {
                fileUploadPath = fileUploadPath + File.separator;
            }
            if(!haveCreatePath) {
                File file = new File(fileUploadPath);
                file.mkdirs();
                haveCreatePath = true;
            }
            return fileUploadPath;
        }
    }

    public void setFileUploadPath(String fileUploadPath){
        this.fileUploadPath = fileUploadPath;
    }

    public Boolean getKaptchaOpen() {
        return kaptchaOpen;
    }

    public void setKaptchaOpen(Boolean kaptchaOpen) {
        this.kaptchaOpen = kaptchaOpen;
    }

    public Boolean getSwaggerOen() {
        return swaggerOen;
    }

    public void setSwaggerOen(Boolean swaggerOen) {
        this.swaggerOen = swaggerOen;
    }

    public Boolean getHaveCreatePath() {
        return haveCreatePath;
    }

    public void setHaveCreatePath(Boolean haveCreatePath) {
        this.haveCreatePath = haveCreatePath;
    }

    public Boolean getSpringSessoinOpen() {
        return springSessoinOpen;
    }

    public void setSpringSessoinOpen(Boolean springSessoinOpen) {
        this.springSessoinOpen = springSessoinOpen;
    }

    public Integer getSessionValidateTime() {
        return sessionValidateTime;
    }

    public void setSessionValidateTime(Integer sessionValidateTime) {
        this.sessionValidateTime = sessionValidateTime;
    }

    public Integer getSessionValidationInterval() {
        return sessionValidationInterval;
    }

    public void setSessionValidationInterval(Integer sessionValidationInterval) {
        this.sessionValidationInterval = sessionValidationInterval;
    }
}
